import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Client from '@/client'
  
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/Register',
    component: () => import('@/views/Client/Register'),
    hidden: true,
    meta: {
      title: '前台',
      type: "Client",

    },
  },
  {
    path: '/404',

    component: () => import('@/views/404'),
    hidden: true,
    meta: {
      type: "foreground",
    },
  },


  { path: '*', redirect: '/', hidden: true }
]
export const constantHomeRoutes = [
  {
    path: '/Client/Index',
    component: Client,
    redirect: "/Client/Home",
    meta: {
      title: '前台',
      type: "Client",

    },
    children: [{
      path: '/Client/Home',
      component: () => import('@/views/Client/Home'),
      name: 'Home',
      hidden: true,
      meta: {
        type: "Client",
        title: '首页',

      }
    }]
  },
]


export const asyncRoutes = [
  {
    path: '/home/index',
    meta: {
      roles: [0, 2],
    },
    component: Layout,
    meta: {
      title: '前台',
      noCache: true,
      roles: [0, 2],
    }
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    meta: {
      roles: [0, 2],
    },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'dashboard',
      meta: {
        roles: [0, 2],
        title: '控制台',
        noCache: true
      }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/Admin/UserList',
    meta: {
      title: '用户管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'UserList',
      component: () => import('@/views/Admin/UserList'),
      name: 'UserList',
      meta: {
        title: '用户',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Activity',
    component: Layout,
    redirect: '/Admin/ActivityList',
    meta: {
      title: '文化研学活动管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'ActivityList',
      component: () => import('@/views/Admin/ActivityList'),
      name: 'ActivityList',
      meta: {
        title: '文化研学活动信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/ActivityMoment',
    component: Layout,
    redirect: '/Admin/ActivityMomentList',
    meta: {
      title: '活动精彩瞬间管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'ActivityMomentList',
      component: () => import('@/views/Admin/ActivityMomentList'),
      name: 'ActivityMomentList',
      meta: {
        title: '活动精彩瞬间信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/ActivityRecord',
    component: Layout,
    redirect: '/Admin/ActivityRecordList',
    meta: {
      title: '活动参加记录管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'ActivityRecordList',
      component: () => import('@/views/Admin/ActivityRecordList'),
      name: 'ActivityRecordList',
      meta: {
        title: '活动参加记录信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/AppUser',
    component: Layout,
    redirect: '/Admin/AppUserList',
    meta: {
      title: '用户管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'AppUserList',
      component: () => import('@/views/Admin/AppUserList'),
      name: 'AppUserList',
      meta: {
        title: '用户信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/ArticleInfo',
    component: Layout,
    redirect: '/Admin/ArticleInfoList',
    meta: {
      title: '资讯管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'ArticleInfoList',
      component: () => import('@/views/Admin/ArticleInfoList'),
      name: 'ArticleInfoList',
      meta: {
        title: '资讯信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/ArticleType',
    component: Layout,
    redirect: '/Admin/ArticleTypeList',
    meta: {
      title: '资讯类型管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'ArticleTypeList',
      component: () => import('@/views/Admin/ArticleTypeList'),
      name: 'ArticleTypeList',
      meta: {
        title: '资讯类型信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Banner',
    component: Layout,
    redirect: '/Admin/BannerList',
    meta: {
      title: '封面管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'BannerList',
      component: () => import('@/views/Admin/BannerList'),
      name: 'BannerList',
      meta: {
        title: '封面信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/BuyCard',
    component: Layout,
    redirect: '/Admin/BuyCardList',
    meta: {
      title: '购物车管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'BuyCardList',
      component: () => import('@/views/Admin/BuyCardList'),
      name: 'BuyCardList',
      meta: {
        title: '购物车信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Comment',
    component: Layout,
    redirect: '/Admin/CommentList',
    meta: {
      title: '话题评论管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'CommentList',
      component: () => import('@/views/Admin/CommentList'),
      name: 'CommentList',
      meta: {
        title: '话题评论信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Good',
    component: Layout,
    redirect: '/Admin/GoodList',
    meta: {
      title: '商品管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'GoodList',
      component: () => import('@/views/Admin/GoodList'),
      name: 'GoodList',
      meta: {
        title: '商品信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/GoodType',
    component: Layout,
    redirect: '/Admin/GoodTypeList',
    meta: {
      title: '商品类型管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'GoodTypeList',
      component: () => import('@/views/Admin/GoodTypeList'),
      name: 'GoodTypeList',
      meta: {
        title: '商品类型信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/OrderDetail',
    component: Layout,
    redirect: '/Admin/OrderDetailList',
    meta: {
      title: '订单明细管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'OrderDetailList',
      component: () => import('@/views/Admin/OrderDetailList'),
      name: 'OrderDetailList',
      meta: {
        title: '订单明细信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/OrderInfo',
    component: Layout,
    redirect: '/Admin/OrderInfoList',
    meta: {
      title: '订单管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'OrderInfoList',
      component: () => import('@/views/Admin/OrderInfoList'),
      name: 'OrderInfoList',
      meta: {
        title: '订单信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Topic',
    component: Layout,
    redirect: '/Admin/TopicList',
    meta: {
      title: '话题管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'TopicList',
      component: () => import('@/views/Admin/TopicList'),
      name: 'TopicList',
      meta: {
        title: '话题信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/TopicType',
    component: Layout,
    redirect: '/Admin/TopicTypeList',
    meta: {
      title: '话题类型管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'TopicTypeList',
      component: () => import('@/views/Admin/TopicTypeList'),
      name: 'TopicTypeList',
      meta: {
        title: '话题类型信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/UserAddress',
    component: Layout,
    redirect: '/Admin/UserAddressList',
    meta: {
      title: '用户地址管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'UserAddressList',
      component: () => import('@/views/Admin/UserAddressList'),
      name: 'UserAddressList',
      meta: {
        title: '用户地址信息',
        roles: [0],
        noCache: true
      }
    }]
  },




]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...constantHomeRoutes, ...asyncRoutes]
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
